package com.neusoft.NEPS.controller; // 请确保包名与你的项目结构一致

import com.neusoft.NEPS.entity.LogEntry;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.StackPane;

public class LogViewController {

    @FXML
    private TableView<LogEntry> logTable;

    @FXML
    private TableColumn<LogEntry, String> categoryColumn;

    @FXML
    public void initialize() {
        categoryColumn.setCellFactory(column -> new TableCell<LogEntry, String>() {
            private final Label label = new Label();
            private final StackPane pane = new StackPane(label);

            {
                label.setStyle("-fx-border-color: #AAAAAA; -fx-border-width: 1; -fx-padding: 3px 10px;");
                pane.setAlignment(Pos.CENTER);
            }

            @Override
            protected void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty || item == null) {
                    setGraphic(null);
                } else {
                    label.setText(item);
                    setGraphic(pane);
                }
            }
        });

        ObservableList<LogEntry> data = FXCollections.observableArrayList(
                new LogEntry("1", "2020-10-10 12:35:36", "辽宁省", "沈阳市"),
                new LogEntry("2", "2020-10-10 12:35:36", "辽宁省", "沈阳市"),
                new LogEntry("3", "2020-10-10 12:35:36", "辽宁省", "沈阳市"),
                new LogEntry("4", "2020-10-10 12:35:36", "辽宁省", "沈阳市"),
                new LogEntry("5", "2020-10-10 12:35:36", "辽宁省", "沈阳市")
        );

        logTable.setItems(data);
    }
}